<template>
	<om-formsub-outer :index="index"><om-autoform ref="autoform" :initConfigData="autoformdata" :initValue="initValue"></om-autoform></om-formsub-outer>
</template>

<script>
import { buildSubFormData, subOnLoad, changeEditor, configSelectData } from '../../../static/js/formUtil.js';
import { ignoreHtml, ptFloat, minusF, getDateStr,multiF} from '@/static/js/common.js';
export default {
	provide() {
		return {
			formPage: this
		};
	},
	data() {
		return buildSubFormData({
			initValue: {
				fileList:[]  //上次保存的文件列表
			},
			postId: '',
			productCache:"mkt-customer-reqquirement-title3-product-cache"
		});
	},
	methods: {
		setPriceNum() {
			let _that = this;
			_that.setExpectTotalPriceNum();
			_that.setTotalPriceNum();
		},
		setExpectTotalPriceNum() {
			let _that = this;
			let projectNumVal = _that.formdata.projectNum;
			let expectUnitPriceNumVal = _that.formdata.expectUnitPriceNum;
			if (projectNumVal && expectUnitPriceNumVal) {
				_that.$refs.autoform.formdata.expectTotalPriceNum = multiF(projectNumVal, expectUnitPriceNumVal);
			}
		},
		setTotalPriceNum() {
			let _that = this;
			let projectNumVal = _that.formdata.projectNum;
			let unitPriceNumVal = _that.formdata.unitPriceNum;
			if (projectNumVal && unitPriceNumVal) {
				_that.$refs.autoform.formdata.totalPriceNum = multiF(projectNumVal, unitPriceNumVal);
			}
		},

		initLoad() {
			let _that = this;
		}
	},
	onLoad(e) {
		let _that = this;
		subOnLoad(_that, e, function() {
			_that.postId = e.postId;
			if (e.configDataCacheKey) {
				uni.getStorage({
					key: e.configDataCacheKey,
					success: function(res) {
						//if (res.data && res.data instanceof Array) {
						if(res.data && Object.prototype.toString.call(res.data)==='[object Array]'){
							_that.autoformdata = res.data;
							Object.assign(_that.initValue, _that.formdata);
							_that.autoformdata[0].order = _that.order;
							changeEditor("title3","projectId",{
								link:"../../public/pageSearch/pageSearch",
								"linkParam":{
									other:JSON.stringify({
									}),
									searchfield:"q",
									namefield:"projectCode",
									notefield:"projectName",
									initload:true,
									url:"productShow/likeSerchPager",
									cachename:_that.productCache,
								}
							},null,_that.autoformdata)
							changeEditor(_that.autoformdata[0].editors, 'fileList', 'fileUploadKey', '23');
							if (_that.formdata.fileList) {
								var tempFileList = [];
								var fileUrlList = _that.formdata.fileList.map(t => {
									tempFileList.push(t.fileSaveName);
									return t.fileSaveName;
								});
								changeEditor(_that.autoformdata[0].editors, 'fileList', 'fileUrlList', fileUrlList);
								changeEditor(_that.autoformdata[0].editors, 'fileList', 'tempFileList', tempFileList);
							}
							_that.initLoad();
						}
					}
				});
			}
		});
	},
	onShow() {
		let _that = this
		if(_that.$refs.autoform){
			uni.getStorage({
				key:_that.productCache,
				success:(res)=>{
					if(res.data){
						let d = res.data
						let formdata = _that.$refs.autoform.formdata
						formdata.projectCode = d.projectCode
						formdata.projectName = d.projectName
						formdata.projectStd = d.projectStd
						formdata.projectUnit = d.projectUnit
						uni.removeStorage({
							key:_that.productCache
						})
					}
				}
			})
		}
	}
};
</script>
